#ifndef __AFX_H__
#define __AFX_H__
#include <windows.h>
class CObject;

struct CRuntimeClass
{
	LPCSTR m_lpszClassName;
	int m_nObjectSize;
	UINT m_wSchema;
	CObject*(__stdcall* m_pfnCreateObject)();
	CRuntimeClass* m_pBaseClass;

	CObject* CreateObject();
	BOOL IsDerivedFrom(const CRuntimeClass* pBaseClass) const;
	CRuntimeClass* m_pNextClass;
};

class CObject
{
public:
	virtual CRuntimeClass* GetRuntimeClass()const;
	virtual ~CObject();
public:
	BOOL IsKindOf(const CRuntimeClass* pClass) const;
public:
	static const CRuntimeClass classCObject;
};

inline CObject::~CObject(){}
#define RUNTIME_CLASS(class_name) ((CRuntimeClass*)&class_name::class##class_name)

#define DECLARE_DYNAMIC(class_name)\
	public:\
	static const CRuntimeClass class##class_name;\
	virtual CRuntimeClass* GetRuntimeClass() const;

#define IMPLEMENT_RUNTIMECLASS(class_name,base_class,wSchema,pfnNew)\
	const CRuntimeClass class_name::class##class_name = {\
#class_name,sizeof(class_name),wSchema,pfnNew,\
	 RUNTIME_CLASS(base_class),NULL};\
	CRuntimeClass* class_name::GetRuntimeClass() const\
	 {return RUNTIME_CLASS(class_name);}

#define IMPLEMENT_DYNAMIC(class_name,base_class_name)\
	IMPLEMENT_RUNTIMECLASS(class_name,base_class_name,0xffff,NULL)


#define DECLARE_DYNCREATE(class_name) \
	DECLARE_DYNAMIC(class_name) \
	static CObject* __stdcall CreateObject();

#define IMPLEMENT_DYNCREATE(class_name,base_class_name)\
	CObject* __stdcall class_name::CreateObject()\
{ return new class_name;}\
	IMPLEMENT_RUNTIMECLASS(class_name,base_class_name,0xFFFF,class_name::CreateObject)

#endif